// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   TestFkClient.java

package com.succez.custom.gssjxt.client;

import com.gs.lzhy.api.GtDataProvide;
import com.gs.lzhy.api.WSGtDataProvideImplService;
import java.io.PrintStream;
import java.net.URL;
import java.util.*;
import java.util.concurrent.*;
import org.codehaus.jackson.map.ObjectMapper;
import org.dom4j.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

// Referenced classes of package com.succez.custom.gssjxt.client:
//            ConfigUtil, WebServiceUtil

public class TestFkClient
    implements Runnable
{

    public void start()
    {
        ConfigUtil.initConfig();
        if(pool == null)
        {
            pool = Executors.newScheduledThreadPool(1);
            TestFkClient client = new TestFkClient();
            pool.scheduleWithFixedDelay(client, 0L, 60L, TimeUnit.SECONDS);
        }
    }

    public void stop()
    {
        pool.shutdown();
        pool = null;
    }

    private TestFkClient()
    {
        user = "GS420000";
        password = "123";
        version = "1.10";
        objMapper = new ObjectMapper();
    }

    public static synchronized TestFkClient getInstance()
    {
        if(instanceFk == null)
        {
            instanceFk = new TestFkClient();
            try
            {
                instanceFk.instance = createGtDataProvide(ConfigUtil.gturl);
                instanceFk.version = WebServiceUtil.getVersion(instanceFk.version, ConfigUtil.gtbackup);
                instanceFk.user = ConfigUtil.username;
                instanceFk.password = ConfigUtil.password;
                instanceFk.initQueue();
            }
            catch(Exception ex)
            {
                log.error("TestFkClient", ex);
                throw new RuntimeException(ex);
            }
        }
        return instanceFk;
    }

    private List getQueue(String key)
    {
        initQueue();
        return (List)queue.get(key);
    }

    private void initQueue()
    {
        if(queue == null)
        {
            queue = new HashMap();
            queue.put("CLEANTAX", new ArrayList());
            queue.put("PENINFO", new ArrayList());
            queue.put("DAILYUP", new ArrayList());
        }
    }

    public void run()
    {
        try
        {
            sendCleanTax();
            sendDailyUp();
            sendAdminPenInfo();
        }
        catch(Exception e)
        {
            e.printStackTrace();
            log.error("run", e);
        }
    }

    public String sendFk(String val)
    {
        System.out.println((new StringBuilder("val:-->")).append(val).toString());
        try
        {
            Document dom = DocumentHelper.parseText(val);
            Element root = dom.getRootElement();
            Element data = root.element("Data");
            for(Iterator iter_record = data.elementIterator("Record"); iter_record.hasNext();)
            {
                Element record = (Element)iter_record.next();
                if(record.element("WSZG") != null)
                {
                    Map taxInfo = new HashMap();
                    taxInfo.put("uniscid", record.elementText("UNISCID"));
                    taxInfo.put("wszg", record.elementText("WSZG"));
                    taxInfo.put("nsrmc", record.elementText("NSRMC"));
                    taxInfo.put("kjswjg", record.elementText("KJSWJG"));
                    taxInfo.put("kjrq", record.elementText("KJRQ"));
                    List ls = getQueue("CLEANTAX");
                    ls.add(taxInfo);
                } else
                if(record.element("NSRZT") != null)
                {
                    Map taxInfo = new HashMap();
                    taxInfo.put("uniscid", record.elementText("UNISCID"));
                    taxInfo.put("zgswjg", record.elementText("ZGSWJG"));
                    taxInfo.put("nsrzt", record.elementText("NSRZT"));
                    taxInfo.put("ybnsrzg", record.elementText("YBNSRZG"));
                    taxInfo.put("nsrxydj", record.elementText("NSRXYDJ"));
                    List ls = getQueue("DAILYUP");
                    ls.add(taxInfo);
                } else
                if(record.element("XZCFXX") != null)
                {
                    List ls = getQueue("PENINFO");
                    String uniscid = record.elementText("UNISCID");
                    Element xzcfxx = record.element("XZCFXX");
                    for(Iterator iter_xzcfxx = xzcfxx.elementIterator("XZCFJDXX"); iter_xzcfxx.hasNext();)
                    {
                        Element jdxx = (Element)iter_xzcfxx.next();
                        String xzcfwsh = jdxx.elementText("XZCFJDWSH");
                        String xzcfswjg = jdxx.elementText("XZCFSWJG");
                        Map taxInfo;
                        for(Iterator iter_jdxx = jdxx.elementIterator("XZCFJD"); iter_jdxx.hasNext(); ls.add(taxInfo))
                        {
                            Element jd = (Element)iter_jdxx.next();
                            String sswfxwzl = jd.elementText("SSWFXWZL");
                            String xzcfnr = jd.elementText("XZCFNR");
                            String xzcfrq = jd.elementText("XZCFJDRQ");
                            taxInfo = new HashMap();
                            taxInfo.put("uniscid", uniscid);
                            taxInfo.put("xzcfwsh", xzcfwsh);
                            taxInfo.put("sswfxwzl", sswfxwzl);
                            taxInfo.put("xzcfnr", xzcfnr);
                            taxInfo.put("xzcfrq", xzcfrq);
                            taxInfo.put("xzcfswjg", xzcfswjg);
                        }

                    }

                }
            }

        }
        catch(DocumentException e)
        {
            e.printStackTrace();
            log.error("sendFk", e);
            return "-1";
        }
        return "1";
    }

    public void sendCleanTax()
        throws Exception
    {
        List taxInfos = getQueue("CLEANTAX");
        queue.put("CLEANTAX", new ArrayList());
        if(taxInfos.size() > 0)
        {
            String jsonStr = objMapper.writeValueAsString(taxInfos);
            System.out.println((new StringBuilder("JSON\uFF1A")).append(jsonStr).append(";user\uFF1A").append(user).append(";password\uFF1A").append(password).toString());
            String resultInfo = getInstance().instance.sendCleanTaxInfo(user, password, jsonStr);
            System.out.println((new StringBuilder("\u4F20\u9012\u6E05\u7A0E\u4FE1\u606F\uFF1A")).append(resultInfo).toString());
        } else
        {
            System.out.println("\u4F20\u9012\u6E05\u7A0E\u4FE1\u606F\uFF1A\u65E0");
        }
    }

    public void sendDailyUp()
        throws Exception
    {
        List taxInfos = getQueue("DAILYUP");
        queue.put("DAILYUP", new ArrayList());
        if(taxInfos.size() > 0)
        {
            String jsonStr = objMapper.writeValueAsString(taxInfos);
            System.out.println((new StringBuilder("JSON\uFF1A")).append(jsonStr).append(";user\uFF1A").append(user).append(";password\uFF1A").append(password).toString());
            String resultInfo = getInstance().instance.sendDailySup(user, password, jsonStr);
            System.out.println((new StringBuilder("\u4F20\u9012\u65E5\u5E38\u4FE1\u606F\uFF1A")).append(resultInfo).toString());
        } else
        {
            System.out.println("\u4F20\u9012\u65E5\u5E38\u4FE1\u606F\uFF1A\u65E0");
        }
    }

    public void sendAdminPenInfo()
        throws Exception
    {
        List taxInfos = getQueue("PENINFO");
        queue.put("PENINFO", new ArrayList());
        if(taxInfos.size() > 0)
        {
            String jsonStr = objMapper.writeValueAsString(taxInfos);
            System.out.println((new StringBuilder("JSON\uFF1A")).append(jsonStr).append(";user\uFF1A").append(user).append(";password\uFF1A").append(password).toString());
            String resultInfo = getInstance().instance.sendAdminPenInfo(user, password, jsonStr);
            System.out.println((new StringBuilder("\u4F20\u9012\u884C\u653F\u5904\u7F5A\u4FE1\u606F\uFF1A")).append(resultInfo).toString());
        } else
        {
            System.out.println("\u4F20\u9012\u884C\u653F\u5904\u7F5A\u4FE1\u606F\uFF1A\u65E0");
        }
    }

    public static GtDataProvide createGtDataProvide()
        throws Exception
    {
        URL url = new URL(ConfigUtil.gturl);
        WSGtDataProvideImplService svr = new WSGtDataProvideImplService(url);
        return svr.getWSGtDataProvideImplPort();
    }

    public static GtDataProvide createGtDataProvide(String uri)
        throws Exception
    {
        URL url = new URL(uri != null ? uri : ConfigUtil.gturl);
        System.out.println(url);
        WSGtDataProvideImplService svr = new WSGtDataProvideImplService(url);
        return svr.getWSGtDataProvideImplPort();
    }

    private static final String TAX_XZCFSWJG = "xzcfswjg";
    private static final String TAX_XZCFRQ = "xzcfrq";
    private static final String TAX_XZCFNR = "xzcfnr";
    private static final String TAX_SSWFXWZL = "sswfxwzl";
    private static final String TAX_XZCFWSH = "xzcfwsh";
    private static final String TAX_NSRXYDJ = "nsrxydj";
    private static final String TAX_YBNSRZG = "ybnsrzg";
    private static final String TAX_NSRZT = "nsrzt";
    private static final String TAX_KJRQ = "kjrq";
    private static final String TAX_KJSWJG = "kjswjg";
    private static final String TAX_NSRMC = "nsrmc";
    private static final String TAX_WSZG = "wszg";
    private static final Logger log = LoggerFactory.getLogger(TestFkClient.class);
    private GtDataProvide instance;
    private static final String TAX_UNISCID = "uniscid";
    private static final String CleanTax = "CLEANTAX";
    private static final String DailyUp = "DAILYUP";
    private static final String PenInfo = "PENINFO";
    private static final String TAX_REG_ZGSWJGMC = "zgswjg";
    private String user;
    private String password;
    private String version;
    private ObjectMapper objMapper;
    private static ScheduledExecutorService pool;
    private static Map queue;
    private static TestFkClient instanceFk;

}
